﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class Level_ShakePhone : MonoBehaviour
{
    public GridLayoutGroup gridLayoutGroup;
    public GameLevelItem gameLevelItem;
    private float newY;
    private float oldY;
    private float tempY;
    private float minTriggerValue = 1.5f;
    public void Update()
    {
        if (!this.enabled) return;
        newY = Input.acceleration.y;
        tempY = newY - oldY;
        if (tempY > minTriggerValue)
        {
            Shake();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            Shake();
        }
    }

    private void Shake()
    {
        float x = gridLayoutGroup.spacing.x;
        if (x > 70)
        {
            TriggerResult();
            return;
        }
        gridLayoutGroup.spacing = new Vector2(x + 20, 0);
        Handheld.Vibrate();
    }

    private void TriggerResult()
    {
        gameLevelItem.TriggerResult(true);
    }

}
